package com.yonyou.pmclouds.problemlog.process;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.problemlog.entity.ProblemLogVO;
import com.yonyou.pmclouds.repairlog.entity.RepairLogVO;
import com.yonyou.pmclouds.repairlog.service.rmiitf.RepairLogService;
/**
 * 添加本次整改记录
 * @author fangpengc
 *
 */
@Component
public class RepairAfterProcess implements SingleProcessor<ProblemLogVO>{
    @Autowired
    private RepairLogService service;
    @Override
    public void process(ProblemLogVO vo, ProblemLogVO orig) throws BusinessException {
        if(vo == null || vo.getRepairlogs() == null || vo.getRepairlogs().length == 0) {
            return;
        }
        RepairLogVO[] repairlogs = vo.getRepairlogs();
        String pk_problemlog = vo.getPk_problem();
        // 添加本次的整改记录
        RepairLogVO newRepair = null;
        for (RepairLogVO repairLogVO : repairlogs) {
            if(repairLogVO.getPk_repair() == null) {
                // 设置问题记录单据主键
                repairLogVO.setPk_problemlog(pk_problemlog);
                // 设置整改日期
                repairLogVO.setRepair_time(new Date());
                newRepair = repairLogVO;
            }
        }
        service.add(newRepair);
    }

}
